package com.baizhi.util;

import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
/*
pom.xml
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-core</artifactId>
  <version>请参见最新版本号</version>
</dependency>
*/
public class SendSms {

    public static void main(String[] args) {
        //修改公钥和私钥
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI5t6d91zGvvtkTr3gD7wY", "x1dDAQOVSE3WE8g91tgpD1qazuTnIb");
        IAcsClient client = new DefaultAcsClient(profile);

        CommonRequest request = new CommonRequest();
        request.setSysMethod(MethodType.POST);

        request.setSysDomain("dysmsapi.aliyuncs.com");
        request.setSysVersion("2017-05-25");
        request.setSysAction("SendSms");
        //修改要接收验证码的手机号码
        request.putQueryParameter("PhoneNumbers", "18834877084");
        //配置以审核通过的签名
        request.putQueryParameter("SignName", "小蛋黄");
        //配置以审核通过的模板code
        request.putQueryParameter("TemplateCode", "SMS_171112532");
        //配置code变量的值
        request.putQueryParameter("TemplateParam", "{\"code\":\"88888888\"}");
        try {
            CommonResponse response = client.getCommonResponse(request);
            System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }
}
